//
// itertool - a polynormial and type-safe iterator framework in C++.
//
// Copyright (c) 2021-2025 Feng Cong
//
// Distributed under the MIT Software License
// See accompanying file LICENSE.txt or copy at
// https://opensource.org/licenses/MIT

#include <itertool/iter/enumerate.h>

#include <algorithm>
#include <iterator>
#include <map>

#include "itertool_test.h"

TEST_CASE("EnumItem usages") {
  itertool::EnumItem<char> item(0, 'a');

  SUBCASE("Can be converted to a pair") {
    std::pair<size_t, char> p = item;
    CHECK_EQ(p.first, item.index);
    CHECK_EQ(p.second, item.value);
  }
}

TEST_CASE("EnumIter") {
  auto en = itertool::Enumerate(itertool_test::NaturalNumber(10), 1);

  SUBCASE("index updates correctly") {
    itertool::EnumIndexType index = 1;
    for (auto item : en) {
      CHECK_EQ(index, item.index);
      ++index;
    }
  }

  SUBCASE("works with stl routines") {
    std::map<int, int> map;
    int index = 1;
    std::copy(en.begin(), en.end(), std::inserter(map, map.end()));
    CHECK_EQ(map.size(), 10);

    for (auto item : map) {
      CHECK_EQ(item.first, index);
      ++index;
    }
  }

#ifdef __cpp_structured_bindings
  SUBCASE("works with structured bindings") {
    for (auto [index, val] : en) {
    }
  }
#endif
}
